package com.ruoyi.project.wms.essentials.details.controller;

import java.util.List;

import com.ruoyi.project.wms.essentials.details.domain.WmsPurchaseDetails;
import com.ruoyi.project.wms.essentials.details.service.IWmsPurchaseDetailsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 进货订单商品Controller
 * 
 * @author ruoyi
 * @date 2020-10-29
 */
@Controller
@RequestMapping("/essentials/details")
public class WmsPurchaseDetailsController extends BaseController
{
    private String prefix = "wms/essentials/purchase";

    @Autowired
    private IWmsPurchaseDetailsService wmsPurchaseDetailsService;

    @RequiresPermissions("essentials:details:view")
    @GetMapping()
    public String details(Long id,ModelMap mmap) {
        mmap.addAttribute("purId",id);
        return prefix + "/details";
    }

    /**
     * 查询进货订单商品列表
     */
    @RequiresPermissions("essentials:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsPurchaseDetails wmsPurchaseDetails)
    {
        startPage();
        List<WmsPurchaseDetails> list = wmsPurchaseDetailsService.selectWmsPurchaseDetailsList(wmsPurchaseDetails);
        return getDataTable(list);
    }

    /**
     * 导出进货订单商品列表
     */
    @RequiresPermissions("essentials:details:export")
    @Log(title = "进货订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsPurchaseDetails wmsPurchaseDetails)
    {
        List<WmsPurchaseDetails> list = wmsPurchaseDetailsService.selectWmsPurchaseDetailsList(wmsPurchaseDetails);
        ExcelUtil<WmsPurchaseDetails> util = new ExcelUtil<WmsPurchaseDetails>(WmsPurchaseDetails.class);
        return util.exportExcel(list, "details");
    }

    /**
     * 新增进货订单商品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存进货订单商品
     */
    @RequiresPermissions("essentials:details:add")
    @Log(title = "进货订单商品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsPurchaseDetails wmsPurchaseDetails)
    {
        return toAjax(wmsPurchaseDetailsService.insertWmsPurchaseDetails(wmsPurchaseDetails));
    }

    /**
     * 修改进货订单商品
     */
    @GetMapping("/edit/{detPurId}")
    public String edit(@PathVariable("detPurId") Long detPurId, ModelMap mmap)
    {
        WmsPurchaseDetails wmsPurchaseDetails = wmsPurchaseDetailsService.selectWmsPurchaseDetailsById(detPurId);
        mmap.put("wmsPurchaseDetails", wmsPurchaseDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存进货订单商品
     */
    @RequiresPermissions("essentials:details:edit")
    @Log(title = "进货订单商品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsPurchaseDetails wmsPurchaseDetails)
    {
        return toAjax(wmsPurchaseDetailsService.updateWmsPurchaseDetails(wmsPurchaseDetails));
    }

    /**
     * 删除进货订单商品
     */
    @RequiresPermissions("essentials:details:remove")
    @Log(title = "进货订单商品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsPurchaseDetailsService.deleteWmsPurchaseDetailsByIds(ids));
    }
}
